home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / deletept.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  6KB  |  227 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "func.h"
  13. #include "object.h"
  14. #include "paintop.h"
  15.  
  16. #define            TOLERANCE    3
  17.  
  18. extern            (*canvas_kbd_proc)();
  19. extern            (*canvas_locmove_proc)();
  20. extern            (*canvas_leftbut_proc)();
  21. extern            (*canvas_middlebut_proc)();
  22. extern            (*canvas_rightbut_proc)();
  23. extern            null_proc();
  24. extern            set_popupmenu();
  25.  
  26. extern F_line        *line_point_search();
  27. extern F_spline        *spline_point_search();
  28. extern int        last_object;
  29. extern int        fix_x, fix_y, cur_x, cur_y;
  30. extern int        pointmarker_shown;
  31.  
  32. extern F_point        *left_point, *right_point;
  33. extern F_point        *deleted_point;
  34. extern F_line        *line;
  35. extern F_spline        *spline;
  36.  
  37.             init_delete_point();
  38.  
  39. delete_point_selected()
  40. {
  41.     canvas_kbd_proc = null_proc;
  42.     canvas_locmove_proc = null_proc;
  43.     canvas_leftbut_proc = init_delete_point;
  44.     canvas_middlebut_proc = null_proc;
  45.     canvas_rightbut_proc = set_popupmenu;
  46.     set_cursor(&pick9_cursor);
  47.     reset_action_on();
  48.     }
  49.  
  50. init_delete_point(x, y)
  51. int     x, y;
  52. {
  53.     F_spline    *spline;
  54.     F_line        *line;
  55.     F_point        *p, *q;
  56.     int        n;
  57.  
  58.     /*
  59.     If the attemp to delete point fails, we wouldn't want any important
  60.     variables (left_point, right_point and delted_point) to change. 
  61.     So we used p and q in the search.
  62.     */
  63.  
  64.     if ((line = line_point_search(x, y, TOLERANCE, &p, &q)) != NULL) {
  65.         if (line->type == T_BOX) {
  66.         put_msg("Deleting box corners is not allowed");
  67.         return;
  68.         }
  69.         n = num_points(line->points);
  70.         if (line->type == T_POLYGON) {
  71.         if (n <= 4) {
  72.             put_msg("A polygon cannot have less than 3 points");
  73.             return;
  74.             }
  75.         }
  76.         else if (n <= 1) {
  77.         put_msg("A line cannot have less than 2 points");
  78.         return;
  79.         }
  80.         clean_up();
  81.         left_point = p;
  82.         deleted_point = q;
  83.         right_point = q->next;
  84.         linepoint_deleting(line);
  85.         set_action_object(F_DELETE_POINT, O_POLYLINE);
  86.         set_latestline(line);
  87.         }
  88.     else if ((spline=spline_point_search(x, y, TOLERANCE, &p, &q)) != NULL){
  89.         n = num_points(spline->points);
  90.         if (closed_spline(spline)) {
  91.         if (n <= 4) {
  92.             put_msg("A closed spline cannot have less than 3 points");
  93.             return;
  94.             }
  95.         }
  96.         else if (normal_spline(spline)) {
  97.         if (n <= 1) {
  98.             put_msg("A spline cannot have less than 2 points");
  99.             return;
  100.             }
  101.         }
  102.         else if (n <= 2) { /* it must be an interpolated spline */
  103.         put_msg("An interpolated spline may have less than 3 points");
  104.         return;
  105.         }
  106.         clean_up();
  107.         left_point = p;
  108.         deleted_point = q;
  109.         right_point = q->next;
  110.         splinepoint_deleting(spline);
  111.         set_action_object(F_DELETE_POINT, O_SPLINE);
  112.         set_latestspline(spline);
  113.         }
  114.     }
  115.  
  116. /**************************  spline  *******************************/
  117.  
  118. splinepoint_deleting(spline)
  119. F_spline    *spline;
  120. {
  121.     F_point        *p;
  122.  
  123.     set_temp_cursor(&wait_cursor);
  124.     if (closed_spline(spline)) {
  125.         pw_batch_on(canvas_pixwin);
  126.         if (pointmarker_shown) toggle_splinepointmarker(spline);
  127.         draw_spline(spline, ERASE); /*erase the spline */
  128.         if (left_point == NULL) { 
  129.         /* The deleted point is the first point */
  130.         spline->points = right_point;
  131.         for (left_point = right_point, p = left_point->next;
  132.             p->next != NULL;
  133.             left_point = p, p = p->next);
  134.         /*
  135.         left_point now points at next to last point
  136.         (the last point is a copy of the first).
  137.         */
  138.         p->x = spline->points->x;
  139.         p->y = spline->points->y;
  140.         right_point = p;
  141.         /*
  142.         Right_point becomes the last point.  If this operation
  143.         (point deletion) is reversed (undo), the deleted_point
  144.         will not be inserted into it original place, but will
  145.         be between left_point and right_point.
  146.         */
  147.         }
  148.         else
  149.         left_point->next = right_point;
  150.         }
  151.     else { /* open spline */
  152.         pw_batch_on(canvas_pixwin);
  153.         if (pointmarker_shown) toggle_splinepointmarker(spline);
  154.         draw_spline(spline, ERASE); /*erase the spline */
  155.         if (left_point == NULL) 
  156.         spline->points = right_point;
  157.         else 
  158.         left_point->next = right_point;
  159.         }
  160.     if (int_spline(spline)) {
  161.         F_control    *c;
  162.  
  163.         c = spline->controls;
  164.         spline->controls = c->next;
  165.         c->next = NULL;
  166.         free((char*)c);
  167.         remake_control_points(spline);
  168.         }
  169.     draw_spline(spline, PAINT);
  170.     if (pointmarker_shown) toggle_splinepointmarker(spline);
  171.     pw_batch_off(canvas_pixwin);
  172.     set_modifiedflag();
  173.     reset_cursor();
  174.     }
  175.  
  176. /***************************  line  ********************************/
  177.  
  178. /*
  179. In deleting a point p, linepoint_deleting uses left_point and
  180. right_point of point p.  The relationship of the three points
  181. are : left_point->p->right_point except when p is the first
  182. point in the list, in which case left_point will be NULL.
  183. */
  184. linepoint_deleting(line)
  185. F_line    *line;
  186. {
  187.     F_point    *p;
  188.  
  189.     if (line->type == T_POLYGON) {
  190.         if (pointmarker_shown) toggle_linepointmarker(line);
  191.         draw_line(line, ERASE); /*erase the line */
  192.         if (left_point == NULL) {
  193.         /* The deleted point is the first point */
  194.         line->points = right_point;
  195.         for (left_point = right_point, p = left_point->next; 
  196.             p->next != NULL; 
  197.             left_point = p, p = p->next);
  198.         /*
  199.         left_point now points at next to last point
  200.         (the last point is a copy of the first).
  201.         */
  202.         p->x = right_point->x;
  203.         p->y = right_point->y;
  204.         right_point = p;
  205.         /*
  206.         Right_point becomes the last point.  If this operation
  207.         (point deletion) is reversed (undo), the deleted_point
  208.         will not be inserted into it original place, but will
  209.         be between left_point and right_point.
  210.         */
  211.         }
  212.         else
  213.         left_point->next = right_point;
  214.         }
  215.     else { /* polyline */
  216.         if (pointmarker_shown) toggle_linepointmarker(line);
  217.         draw_line(line, ERASE); /*erase the line */
  218.         if (left_point == NULL) 
  219.         line->points = right_point;
  220.         else 
  221.         left_point->next = right_point;
  222.         }
  223.     draw_line(line, PAINT);
  224.     if (pointmarker_shown) toggle_linepointmarker(line);
  225.     set_modifiedflag();
  226.     }
  227.